
package com.lht.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lht.admin.annotation.SysLog;
import com.lht.admin.entity.OrderEntity;
import com.lht.admin.service.OrderService;
import com.lht.admin.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单表Controller
 *
 * @author ZhengZhanWu
 * @date 2020-02-06 13:42:45
 */
@RestController
@RequestMapping("/order")
public class OrderController extends AbstractController {
    @Autowired
    private OrderService orderService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("order:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<OrderEntity> list = orderService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询订单表
     *
     * @param params 查询参数
     * @return R
     */
    @GetMapping("/list")
    @RequiresPermissions("order:list")
    public R list(@RequestParam Map<String, Object> params) {
        Page page = orderService.queryPage(params);

        return R.ok().put("page", parseToPageUtils(page));
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("order:info")
    public R info(@PathVariable("id") Long id) {
        OrderEntity order = orderService.queryById(id);
        return R.ok().put("order", order);
    }

    /**
     * 新增订单表
     *
     * @param order order
     * @return R
     */
    @SysLog("新增订单表")
    @RequestMapping("/save")
    @RequiresPermissions("order:save")
    public R save(@RequestBody OrderEntity order) {

        orderService.add(order);

        return R.ok();
    }

    /**
     * 修改订单表
     *
     * @param order order
     * @return R
     */
    @SysLog("修改订单表")
    @RequestMapping("/update")
    @RequiresPermissions("order:update")
    public R update(@RequestBody OrderEntity order) {

        orderService.update(order);

        return R.ok();
    }

    /**
     * 根据主键删除订单表
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除订单表")
    @RequestMapping("/delete")
    @RequiresPermissions("order:delete")
    public R delete(@RequestBody Long[] ids) {
        orderService.deleteBatch(ids);

        return R.ok();
    }
}
